package com.bing.picture;

import static com.bing.util.AssertUtils.notBlank;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class LocalPicture extends AbastractPicture {
	
	public LocalPicture(String pictureUrl) {
		this(pictureUrl, pictureUrl);
	}
	
	public LocalPicture(String pictureUrl, String pk) {
		super(new LocalPictureStream().stream(pictureUrl), pk);
		this.pictureUrl = pictureUrl;
	}

	@Override
	public String name() {
		return null;
	}

	static class LocalPictureStream implements PictureStream {

		@Override
		public InputStream stream(String pictureUrl) {
			
			notBlank(pictureUrl, "picture url must not be blank!");
			InputStream inputStream = null;
			try {
				inputStream = new FileInputStream(new File(pictureUrl));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			return inputStream;
		}
	}
	
}
